home *** CD-ROM | disk | FTP | other *** search
/ PC Magazine Extra 1998 Summer: The Perfect PC / PC Magazine Extra - The Perfect PC - Summer 1998 Vol 6 #2.iso / dwzdika / 1504 / delb4.bat next >
DOS Batch File  |  1995-10-27  |  2KB  |  78 lines

  1. @ECHO OFF
  2. REM DELB4.BAT - delete files before a given date
  3. REM   (the name DELB4.BAT is hard-coded; don't change)
  4.  
  5. IF '%2'=='' GOTO Syntax
  6. IF NOT EXIST %1 GOTO NotExist
  7. FOR %%v IN (%1) DO IF '%%v'=='%1' GOTO NoWildcard
  8. CLS
  9. ECHO DELB4.BAT: Deleting files matching %1 dated before %2
  10. ECHO.
  11. xcopy %1 /I /L /d:%2 nothing > NEWER$$1.$$$
  12. IF ERRORLEVEL 1 GOTO Error
  13.  
  14. find /v "File(s)" < NEWER$$1.$$$ > NEWER$$2.$$$
  15. FC NEWER$$2.$$$ NUL /LB200 /N | DATE | FIND ":  " > EN#ER.BAT
  16. del NEWER$$2.$$$
  17. :: EN#ER.BAT now contains lines of the form
  18. :: "Enter new date (mm-dd-yy):      1:  delb4.bat"
  19. :: Each call to EN#ER.BAT invokes ENTER.BAT once,
  20. :: protecting first file and stripping first line
  21. :: from EN#ER.BAT. Now create ENTER.BAT:
  22.  
  23. ECHO REN EN#ER.BAT EN@ER.BAT>ENTER.BAT
  24. ECHO %%"%% FIND /V " %%4" < EN@ER.BAT > EN#ER.BAT %%"%%>>ENTER.BAT
  25. ECHO DEL EN@ER.BAT>>ENTER.BAT
  26. ECHO SET DidEnter=Yes>>ENTER.BAT
  27. ECHO IF NOT EXIST %%5 SET DidEnter=Err>>ENTER.BAT
  28. ECHO ATTRIB +R %%5>>ENTER.BAT
  29.  
  30. :Loop
  31. SET DidEnter=
  32. CALL EN#ER.BAT
  33. IF '%DidEnter%'=='Yes' GOTO Loop
  34. IF '%DidEnter%'=='Err' GOTO NotCur
  35.  
  36. SET DidEnter=
  37. DEL EN?ER.BAT
  38. IF EXIST DELB4.BAT ATTRIB +R DELB4.BAT
  39. ECHO Files to be deleted:
  40. DIR %1 /A-D-R /O-D | Find "-" | Find /v "e"
  41. CHOICE Ok to delete these files
  42. IF ERRORLEVEL 2 GOTO Nope
  43. ECHO Y | DEL %1 > NUL
  44. :Nope
  45. ATTRIB -R %1
  46. IF EXIST DELB4.BAT ATTRIB -R DELB4.BAT
  47. DEL NEWER$$1.$$$
  48.  
  49. GOTO End
  50.  
  51. :   NoWildcard ========
  52. ECHO %1 does not include any * or ? wildcards
  53. :   Syntax ========
  54. ECHO Syntax: DELB4 filespec mm/dd/yy
  55. ECHO    where filespec is a wildcard file specification
  56. ECHO    in the current directory
  57. GOTO End
  58.  
  59. :   NotExist ========
  60. ECHO Sorry, no files match %1.
  61. GOTO End
  62.  
  63. :   NotCur ========
  64. SET DidEnter=
  65. DEL EN?ER.BAT
  66. DEL NEWER$$1.$$$
  67. ECHO The first parameter to DELB4.BAT should not contain
  68. ECHO path information. DELB4.BAT is meant to work in the
  69. ECHO current directory. The error that happened suggests
  70. ECHO that the first parameter referred to files in some
  71. ECHO other directory.
  72. GOTO End
  73.  
  74. :   Error ========
  75. ECHO Error with XCOPY; probably %2 is a bad date
  76.  
  77. :   End ========
  78.